/*******************************************************************
 *
 * Copyright (C), 2021-2022, Letstrong, All rights reserved.
 *
 * Author      : 
 * Create Time : 2020-12-12
 * Version     : v0.1
 * Description : 
 *******************************************************************/
 
/*----------------------------Head file----------------------------*/
#include "hal_pwr_mgr.h"
#include "user_config.h"
#include "icu.h"
#include "wdt.h"
#include "app_task.h"

/*----------------------------macro file---------------------------*/

/*----------------------------type define--------------------------*/

/*----------------------------var define---------------------------*/
static bool sleep_mode = false;

/*-------------------------func declaration------------------------*/

/*-----------------------------------------------------------------*/

void hal_pwr_sleep_enable(void)
{
	if(true == sleep_mode)
		return;

	icu_set_sleep_mode(0);
	rwip_prevent_sleep_clear(BK_DRIVER_TIMER_ACTIVE);
	sleep_mode = true;
}

void hal_pwr_sleep_disable(void)
{
	if(false == sleep_mode)
		return;

	//Do not ctrl watchdog here, BK SDK enable it and feed it by starting advertisement, or it may cause system reset.
	icu_set_sleep_mode(1); //Exit from deep sleep mode.
	rwip_prevent_sleep_set(BK_DRIVER_TIMER_ACTIVE);
	sleep_mode = false;
}


